package com.niiwoo.civet.trade.dao.mapper;

import org.apache.ibatis.annotations.Param;

import com.niiwoo.civet.trade.dao.entity.KaoLaRealRepayment;

import java.util.List;


/**
 * @author liming
 * @date 2017-12-25 18:30
 */
public interface KaoLaRealRepaymentMapperExt extends KaoLaRealRepaymentMapper{
	KaoLaRealRepayment queryLastKaoLaRealRepaymentOrderByProjectIdAndRepayNo(@Param("projectId")Long projectId, @Param("repayNo")Integer repayNo);

	/**
	 * 是否有回购(包括主动和被动回购)
	 *
	 * @param projectId	项目id
	 * @return KaoLaRealrePayment
	 */
	KaoLaRealRepayment selectKaoLaBuyBack(Long projectId);

	/**
	 * 根据还款类型查询某个标的最新一条处理请求
	 *
	 * @param projectId 项目ID
	 * @param repayMethod 还款类型：3：正常还款、4：提前还款、5：逾期代偿
	 * @return
	 */
	KaoLaRealRepayment selectRepaymentByRepayMethod(@Param("projectId")Long projectId,@Param("repayMethod")Byte repayMethod);

	/**
	 * 根据项目id查询正在处理中的还款请求数
	 *
	 * @param projectId 项目ID
	 * @return
	 */
	int countProcessingRepay(@Param("projectId")Long projectId);


    /**
     *
     * @Description 根据项目和流水查询还款记录
     * @param repaySerialNo
     * @param subjectId
     * @return KaoLaRealrePayment
     *
     */
    KaoLaRealRepayment selectPaymentBySerialNoAndSubjectIdForUpdate(@Param("repaySerialNo")String repaySerialNo, @Param("subjectId")String subjectId);


    /**
     * 查询成功代偿的记录
     * @param projectId
     * @param repayNo
     * @return
     */
    KaoLaRealRepayment selectSuccessAdvanceByProjectIdAndPeriod(@Param("projectId")Long projectId,@Param("repayNo")Integer repayNo);


    /**
     * 是否包括被动回购
     *
     * @param projectId
     * @return KaoLaRealrePayment
     */
    KaoLaRealRepayment selectPassiveKaoLaBuyBack(@Param("projectId")Long projectId);

	List<KaoLaRealRepayment> selectRepayedAdvance(@Param("projectId")Long projectId, @Param("repayType")Byte repayType);


	/**
	 * 是否包括被动批扣
	 *
	 * @param projectId
	 * @return KaoLaRealrePayment
	 */
	KaoLaRealRepayment selectPassiveKaoLaBatchRepayment(@Param("projectId")Long projectId, @Param("repayNo")Integer repayNo);


	int selectBySerialNoAndSubjectId(@Param("repaySerialNo")String repaySerialNo,@Param("subjectId")String subjectId);


	/**
	 *
	 * @Description 查询今日需要获取还款结果的请求列表
	 * @return List<KaoLaRealrePayment>
	 *
	 */
	List<KaoLaRealRepayment> selectNeedGetRepayResultList();
}
